﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace SystemAnalizer.Common
{
    public class ViewHelper
    {
        public static void FaddeevTraceAdder(StackPanel container,double[,] matrix,bool invert,int systemsize,int disc_num)
        {
            if (matrix == null)
                return;
            string cont = "";
            for (int l = 0; l < systemsize; l++)
            {
                StackPanel pnl = new StackPanel();
                Label lbl = new Label();
                lbl.Content = string.Format("Self polynom coeficent {0}, P{0}", l+1);
                pnl.Children.Add(lbl);

                Label lblcoef = new Label();
                cont = string.Format("P{0}=", l + 1);
                Grid grd = new Grid();
             
                    RowDefinition row = new RowDefinition();
                    row.MinHeight = 22;
                    grd.RowDefinitions.Add(row);
                    for (int j = 0; j < disc_num; j++)
                    {
                        ColumnDefinition column = new ColumnDefinition();
                        column.MinWidth = 20;
                        grd.ColumnDefinitions.Add(column);
                        Label valuelbl = new Label();
                        valuelbl.Content = matrix[l, j];

                        if (matrix[l, j] != 0)
                        {
                           // if (j + 1 < disc_num && matrix[l, j + 1] > 0)
                         //       cont += string.Format("{0}t^{1}+", matrix[l, j], j);
                         //   if (j + 1 < disc_num && matrix[l, j + 1] < 0)
                            if (j > 0 && matrix[l, j]>0)
                                cont += string.Format("+{0}t^{1}", matrix[l, j], j);
                            else
                                cont += string.Format("{0}t^{1}", matrix[l, j], j);
                        }
                        
                        
                        Grid.SetRow(valuelbl, 0);
                        Grid.SetColumn(valuelbl, j);
                        grd.Children.Add(valuelbl);
                       
                    }
                lblcoef.Content = cont;
                pnl.Children.Add(lblcoef);
                pnl.Children.Add(grd);  
                container.Children.Add(pnl);
            }
        }

    }
}
